home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Mailcheck Source / init src / mmc_drvr_install.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-18  |  2.4 KB  |  94 lines  |  [TEXT/KAHL]

  1. /*
  2.  * install the mac mail watch driver
  3.  * by Aaron Wohl (aw0g+@andrew.cmu.edu) jul 1990
  4.  * Carnegie-Mellon University
  5.  * Special Projects
  6.  * Pittsburgh, PA 15213-3890
  7.  * (412)-268-5032
  8.  *
  9.  * special thanks to Luni and Rich Brown @ Dartmouth
  10.  *
  11.  * Luni wrote the MacTCP emulator for macmach from which this file
  12.  * borrows liberaly.
  13.  *
  14.  * Rich Brown provided the source to Dartmouth's BlitzNotify installer
  15.  * which was a big help.
  16.  */
  17.  
  18. #include "mmc_drvr_find.h"
  19. #include "mmc_drvr_install.h"
  20. #include "mmc_os_preserve.h"
  21.  
  22. pascal void _DrvrInstall(void) = 0xa03d;
  23.  
  24. /*   FUNCTION DrvrInstall(drvrHandle:Handle; refNum: INTEGER): OSErr; */
  25. short DrvrInstall(Handle drvrHandle, short dRef);
  26. short DrvrInstall(Handle drvrHandle, short dRef)
  27. {
  28.     asm {
  29.         move.w dRef,d0
  30.         move.l drvrHandle,a0
  31. #ifdef RUBBISH
  32.         /*
  33.          * the tech note says it wants pointer not a handle
  34.          * but it seems to be way wrong.
  35.          */
  36.         move.l (a0),a0
  37. #endif
  38.     }
  39.     _DrvrInstall();
  40. }
  41.  
  42. static long find_or_install(int *refnum);
  43. static long find_or_install(int *refnum)
  44. {
  45.     int found_ref;
  46.     short free_ref;
  47.     short err;
  48.     Handle drvr;
  49.     DCtlHandle dCtl;
  50.  
  51.     found_ref = mmc_drvr_find(MMC_name,&free_ref);
  52.     if(found_ref!=0) {
  53.         *refnum=found_ref;    /*found it already open*/
  54.         return 0;            /*no error*/
  55.     }
  56.  
  57.     /*
  58.      * The resource name is .RawMailCheck.
  59.      * The name inside the driver is .MailCheck
  60.      * Having them be different seems to help OpenDriver below
  61.      * pick the one DrvrInstall made up
  62.      */
  63.     if((drvr = GetNamedResource('DRVR',MMC_driver_resource))==0)
  64.         return -192;        /*resource not found*/
  65.  
  66.     HLock(drvr);            /*tech note says to do this*/
  67.     if((err = DrvrInstall(drvr,free_ref))!=0)
  68.         return err;            /*oops, this leaves driver in sys heap
  69.                              * in our case CloseResFile will nuke it
  70.                              */
  71.     /*
  72.      * Drvr install doesn't do anything except fill in dCtlRefNum
  73.      * so follow up and copy over the drivers info
  74.      */
  75.     dCtl = GetDCtlEntry(free_ref);
  76.     (*dCtl)->dCtlDriver = (Ptr) drvr;    /*use handle, teche not is wrong*/
  77.     (*dCtl)->dCtlStorage = (Handle) 0L;
  78.     (*dCtl)->dCtlDelay = *(short *)(*(char **)drvr + 2);
  79.     (*dCtl)->dCtlEMask = *(short *)(*(char **)drvr + 4);
  80.     (*dCtl)->dCtlFlags |= **(short **)drvr;
  81.     DetachResource(drvr);    /*leave it around when CloseResFile happens*/
  82.     return err;
  83. }
  84.  
  85. /*
  86.  * install the mac mail check driver
  87.  */
  88. short mmc_drvr_find_or_install(short *refnum)
  89. {
  90.     return OSP_protected_call(OSP_sys,find_or_install,refnum);
  91. }
  92.  
  93.  
  94.